#!usr/bin/env node

const Koa = require('koa'),
      bodyparser = require('koa-bodyparser'),
      Router = require('koa-router');

const app = new Koa(),
      router = new Router(),
      log = console.log;

app.use(bodyparser());
router.prefix('/authors');

router.get('/',async (ctx,next)=>{
  const {page,limit} = ctx.query;

  log(ctx.header['user-agent']);
  log(ctx.request.headers)
  log(`page=${page},limit=${limit}`)
  ctx.body = "查询成功";

})

router.get('/:authorName',async (ctx,next)=>{
  const {authorName} = ctx.params;
  log(`authorName=${authorName}`);
  ctx.body = "查询成功";
})

router.post('/',async (ctx,next)=>{
  const {authorName} = ctx.request.body;
  log(`authorName=${authorName}`);
  ctx.body="添加成功";
})

app.use(router.routes());
app.listen(8080);
